import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 欢迎
///
class Welcome extends StatefulWidget {
  const Welcome({Key? key}) : super(key: key);

  @override
  State<Welcome> createState() => _WelcomeState();
}

class _WelcomeState extends State<Welcome> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: false,
        backgroundColor: Colors.white,
        elevation: 0,
        systemOverlayStyle: SystemUiOverlayStyle.dark,
      ),
      body: Container(
        decoration: const BoxDecoration(color: Colors.white),
        child: Column(
          children: [
            Expanded(
                child: Column(
                  children: [
                    Container(
                        margin: const EdgeInsets.only(top: Sizes.default100),
                        alignment: Alignment.center,
                        child: GFImageOverlay(
                            height: Sizes.default100,
                            width: Sizes.default100,
                            borderRadius: const BorderRadius.all(Radius.circular(Sizes.default8)),
                            image: ToolsUtils.assetImageIcon('logo.png'))),
                    Container(
                      alignment: Alignment.center,
                      margin: const EdgeInsets.only(top: Sizes.default20, bottom: Sizes.default10),
                      child: Text(
                        '小店外卖',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color333, fontSize: Sizes.default36),
                      ),
                    ),
                    Container(
                      alignment: Alignment.center,
                      margin: const EdgeInsets.only(top: Sizes.default20, bottom: Sizes.default10),
                      child: Text(
                        '—— 商家中心 ——',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color333, fontSize: Sizes.default16),
                      ),
                    )
                  ],
                )),
            Container(
              padding: const EdgeInsets.symmetric(vertical: Sizes.default30),
              child: Column(
                children: [
                  Container(
                    width: double.maxFinite,
                    height: Sizes.default50,
                    margin: const EdgeInsets.symmetric(horizontal: Sizes.default40),
                    child: GFButton(
                        onPressed: showSingleButtonDialog,
                        text: '登录',
                        textStyle: StylesUtils.customTextStyle(fontSize: Sizes.default16),
                        shape: GFButtonShape.pills,
                        type: GFButtonType.solid,
                        size: GFSize.LARGE,
                        color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6)),
                  ),
                  Container(
                    width: double.maxFinite,
                    height: Sizes.default50,
                    margin: const EdgeInsets.only(
                        left: Sizes.default40, right: Sizes.default40, top: Sizes.default20),
                    child: GFButton(
                      onPressed: () {
                        Get.toNamed(RouteGet.storeOpen);
                      },
                      text: '我要开店',
                      textStyle: StylesUtils.customTextStyle(
                          color: ColorsUtils.colorFf6, fontSize: Sizes.default16),
                      shape: GFButtonShape.pills,
                      type: GFButtonType.outline,
                      size: GFSize.LARGE,
                      borderSide: BorderSide(
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6)),
                    ),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  void showSingleButtonDialog() {
    showDialog<void>(
        context: context,
        builder: (BuildContext context) {
          return BrnDialog(
            themeData: BrnDialogConfig(
              dialogWidth: 300,
              radius: Sizes.default10,
              backgroundColor: Colors.white,
              titlePaddingLg: EdgeInsets.zero,
              titlePaddingSm: EdgeInsets.zero,
              titleTextAlign: TextAlign.center,
              contentPaddingLg: EdgeInsets.zero,
              contentPaddingSm: EdgeInsets.zero,
              contentTextAlign: TextAlign.left,
            ),
            titleWidget: Container(
              height: Sizes.default50,
              alignment: Alignment.center,
              child: Text('温馨提示',
                  style: StylesUtils.customTextStyle(
                      fontSize: Sizes.default18, color: ColorsUtils.color000)),
            ),
            contentWidget: Container(
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default10),
              child: Column(
                children: [
                  Container(
                      alignment: Alignment.centerLeft,
                      child: Text.rich(TextSpan(children: [
                        TextSpan(
                            text: '欢迎使用"小默外卖商家中心"！我们非常重视您的个人信息和隐私保护。在您要使用本软件前，请仔细阅读',
                            style: StylesUtils.customTextStyle(
                                fontSize: Sizes.default16, color: ColorsUtils.color333)),
                        TextSpan(
                            text: '《用户协议》《隐私政策》',
                            style: StylesUtils.customTextStyle(
                                fontSize: Sizes.default16, color: ColorsUtils.colorFf6)),
                        TextSpan(
                            text:
                                '如您同意并接受全部条款，请点击"同意"并开始使用我们的产品和服务，我们将严格按照经您同意的各项条款使用您的个人信息，以便为您提供更好的服务，并尽全力保护您的个人信息安全。',
                            style: StylesUtils.customTextStyle(
                                fontSize: Sizes.default16, color: ColorsUtils.color333)),
                      ]))),
                  Container(
                    alignment: Alignment.center,
                    padding: const EdgeInsets.only(top: Sizes.default15),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        SizedBox(
                          width: 120,
                          height: Sizes.default40,
                          child: GFButton(
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                              text: '不同意',
                              textStyle: StylesUtils.customTextStyle(fontSize: Sizes.default16, color: ColorsUtils.color666),
                              shape: GFButtonShape.pills,
                              type: GFButtonType.outline,
                              size: GFSize.LARGE,
                              color: ColorsUtils.parseColorFromHexString(ColorsUtils.color999)),
                        ),
                        SizedBox(
                          width: 120,
                          height: Sizes.default40,
                          child: GFButton(
                              onPressed: () {
                                Navigator.of(context).pop();
                                Future.delayed(const Duration(milliseconds: 50), () {
                                  Get.toNamed(RouteGet.userLoginLogin);
                                });
                              },
                              text: '同意',
                              textStyle: StylesUtils.customTextStyle(
                                  fontSize: Sizes.default16),
                              shape: GFButtonShape.pills,
                              type: GFButtonType.solid,
                              size: GFSize.LARGE,
                              color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6)),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ),
          );
        });
  }
}
